/**
 * Created by Wilson on 3/18/2015.
 */
(function () {
    angular.module('app')
        .factory('userService', userService);

    userService.$inject = ['$window', 'configManager', 'httpService'];
    function userService($window, configManager, httpService) {
        var US = {
            register: register,
            login: login,
            updatePwd: updatePwd,
            getTokenId: getTokenId,
            submitSuggestion: submitSuggestion
        }

        function submitSuggestion(msg) {
            var url = configManager.HOST + 'userSugg/addUserSugg';
            var memberId = $window.localStorage.getItem('user.memberId');
            var params = {
                userID: memberId || 'test',
                content: msg
            };
            return httpService.httpPost(url, params);
        }

        function getTokenId() {
            $window.localStorage.getItem('user.tokenId');
        }

        function updatePwd(loginName, loginPwd) {
            var url = configManager.HOST + 'user/updatePwd'
            var params = {
                loginName: loginName,
                loginPwd: loginPwd
            };
            return httpService.httpPost(url, params);
        }

        function login(loginName, loginPwd) {
            var url = configManager.HOST + 'user/login';
            var params = {
                loginName: loginName,
                loginPwd: loginPwd
            };
            return httpService.httpPost(url, params);
        }

        function register(membermobile, memberPwd, levelId, detailSex, detailName) {
            var url = configManager.HOST + 'user/regist';
            var params = {
                membermobile: membermobile,
                memberPwd: memberPwd,
                levelId: levelId,
                detailSex: detailSex,
                detailName: detailName
            };
            return httpService.httpPost(url, params);
        }


        return US;
    }
})();